use crate::models::AiFlagResult;
use std::io;
use std::io::Result;

const FLAG_NAME: &str = ".ai_db";

pub fn check_ai_flag() -> Result<AiFlagResult> {
    let current_path = std::env::current_dir()?;

    let parent_path = current_path
        .parent()
        .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Failed to get parent directory"))?;

    let flag_path = parent_path.join(FLAG_NAME);
    let no_ai_flag = !flag_path.exists();

    // 构造返回结果
    let result = AiFlagResult {
        no_ai_flag,
        root_path: parent_path.to_path_buf(),
        working_path: current_path,
        flag_name: FLAG_NAME.to_string(),
    };

    Ok(result)
}
